package simorg.actions;

import simorg.controller.UserController;
import simorg.domain.persistence.UserTable;
import simorg.view.ModelView;
import simorg.view.WebSessionContext;

public class UserDelete extends Action {

	public static String actionName = "delete";
	public UserDelete() {
		super(actionName);
		this.controllerName = UserController.controllerName;
	}
	
	@Override
	public ModelView checkAccess(WebSessionContext wc) throws Exception {
		return this.checkAdminAccess(wc);
	}
	
	@Override
	public ModelView process(WebSessionContext wc) throws Exception {
		int id = Integer.parseInt(this.getRequestArgs().get(0));
		UserTable.deleteById(wc.getDbConnection(), id);
		wc.redirectAdmin(new UserList());
		return null;
	}

}
